/*
 * Copyright 2010-2012 Susanta Tewari. <freecode4susant@users.sourceforge.net>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package genomemap.netbeans.jobs1.tab08;

import cef.command.Command;
import cef.pui.EventConstructionException;
import commons.anneal.cef.command.FindSAMapCommand;
import commons.anneal.cef.command.listener.AnnealTextReporter;
import commons.anneal.cef.command.listener.FindSAMapCommandPrintWriter;
import commons.anneal.cef.pui.FindSAMapLHoodEventImpl;
import commons.anneal.nb.jobs.properties.AnnealPropertys;
import commons.nb.jobs.CommonsJobPropertys;
import commons.nb.jobs.Job;
import commons.nb.jobs.properties.BuilderProperty;
import commons.nb.jobs.properties.ComboPropertyImpl;
import commons.nb.jobs.properties.Property;
import genomemap.data.TAB08Data;
import genomemap.model.TAB08;

import java.util.Properties;

import static genomemap.nb.jobs.properties.Propertys_Gen.ALGO_LHOOD_TAB08;
import static genomemap.nb.jobs.properties.Propertys_Gen.BUILDER_DATA_TAB08Data;

/**
 * @author Susanta Tewari
 * @history First created on May 29, 2012
 */
public class FindSAMapLHoodTAB08Job extends Job<FindSAMapLHoodEventImpl<String, TAB08, TAB08Data>> {

    private final BuilderProperty prop_data;
    private final Property<String> prop_algo;

    public FindSAMapLHoodTAB08Job() {

        setName("find-map-tab08-sa");
        setDisplayName("Find Map TAB08-SA");
        setShortDescription("Find TAB08 map using simulated annealing");


        // data & lhood
        addComboProperty(prop_data = BUILDER_DATA_TAB08Data());    // data
        addComboProperty(new ComboPropertyImpl(prop_algo = ALGO_LHOOD_TAB08()));    // lhood


        // SA-properties
        addComboProperty(new ComboPropertyImpl(AnnealPropertys.MasterIterationCount()));
        addComboProperty(new ComboPropertyImpl(AnnealPropertys.MaxBeatenCount()));
        addComboProperty(new ComboPropertyImpl(AnnealPropertys.MaxUnBeatenCount()));
        addComboProperty(new ComboPropertyImpl(AnnealPropertys.TempIterationCount()));
        addComboProperty(new ComboPropertyImpl(AnnealPropertys.StartTemp()));
        addComboProperty(new ComboPropertyImpl(AnnealPropertys.TempFriction()));


        // listeners
        addCommandOutputListener(new FindSAMapCommandPrintWriter.S_BD());
        addJobProperty(
            CommonsJobPropertys.BOOLEAN_EXE_JOB_PROPERTY(
                new AnnealTextReporter.SA.S_BD(),
                AnnealPropertys.ANNEAL_TEXT_REPORTER_BOOLEAN_PROP()));
    }

    @Override
    protected FindSAMapLHoodEventImpl<String, TAB08, TAB08Data> createEvent()
            throws EventConstructionException {

        prop_data.setKeyPrefix("commons.builder.SALHood.data");
        prop_algo.setKeyPrefix("commons.builder.SALHood.LHood");

        final Properties properties = getProperties();

        //J- delegates for data & lhood
        properties.setProperty("commons.builder.SALHood.data.delegate",prop_data.getValue().getBuilderString());
        properties.setProperty("commons.builder.SALHood.LHood.delegate","genomemap.cef.pui.pob.Builders_Gen$LHoodComputer_TAB08");//J+


        return new FindSAMapLHoodEventImpl<>(properties);
    }

    @Override
    protected Command createCommand(final FindSAMapLHoodEventImpl<String, TAB08, TAB08Data> event) {
        return new FindSAMapCommand<>(event);
    }

    @Override
    public boolean isCancellable() {
        return FindSAMapCommand.isCancellable();
    }

    @Override
    public Class<FindSAMapLHoodEventImpl> getEventImplType() {
        return FindSAMapLHoodEventImpl.class;
    }
}
